﻿
package bsplib.q3bsp;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
import flash.utils.ByteArray;

class Q3LightMap 
{
    public static inline var DIR_INDEX : UInt = 14;
    
    public var ldata : BitmapData;
    public function new( data : ByteArray ) 
    {
        ldata = new BitmapData(128, 128, false, 0);
        
        for ( y in 0...128 )
        for ( x in 0...128 ) {
            var r = data.readUnsignedByte();
            var g = data.readUnsignedByte();
            var b = data.readUnsignedByte();
            ldata.setPixel( x, y, r << 16 | g << 8 | b );
        }
        
        var ldata2 = new BitmapData( 512, 512, false, 0);
        var m = new Matrix();
        m.identity();
        m.scale(4, 4);
        
        var ambient = 0.1;
        var ambientCT = new ColorTransform(1 - ambient, 1 - ambient, 1 - ambient, 1, ambient * 255, ambient * 255, ambient * 255, 0);
        ldata2.draw(ldata, m, ambientCT, null, null, true);
        ldata = ldata2;
    }
    
}